package com.linfeng.component.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.linfeng.component.mybatisplus.event.cmd.CreateCmd;
import com.linfeng.component.mybatisplus.event.cmd.UpdateCmd;
import com.linfeng.component.mybatisplus.event.qry.PageQry;
import com.linfeng.component.mybatisplus.executor.cmd.CreateCmdExe;
import com.linfeng.component.mybatisplus.executor.cmd.UpdateCmdExe;
import com.linfeng.component.mybatisplus.executor.qry.DetailQryExe;
import com.linfeng.component.mybatisplus.executor.qry.PageQryExe;
import com.linfeng.component.mybatisplus.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;

public class BaseServiceImpl<D, PQ extends PageQryExe, DQ extends DetailQryExe,
        CE extends CreateCmdExe, UE extends UpdateCmdExe, CC extends CreateCmd, UC extends UpdateCmd> implements BaseService<D,CC, UC> {

    @Autowired
    private PQ pageQryExe;

    @Autowired
    private DQ detailQryExe;

    @Autowired
    private CE createCmdExe;

    @Autowired
    private UE updateCmdExe;

    public <Q extends PageQry> IPage page(Q q) {

        return pageQryExe.execute(q);
    }

    @Override
    public boolean create(CC cmd) {
        return createCmdExe.execute(cmd);
    }

    @Override
    public boolean update(UC cmd) {
        return updateCmdExe.execute(cmd);
    }

    @Override
    public D detail(Serializable id) {
        return (D) detailQryExe.execute(id);
    }
}
